<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>列表渲染练习</title>
</head>
<body>
    <ul id="example-1">
        <li v-for="(item, index) of items">
            {{parentMessage}} - {{index}} - {{ item.message }}
        </li>
    </ul>
    <ul id="v-for-object" class="demo">
        <li v-for="(value, name, index) in object">
            {{ index }}. {{ name }}: {{ value }}
        </li>
    </ul>
    <ul id='evenNumber' v-for="set in sets">
        <li v-for="n in even(set)">{{ n }}</li>
    </ul>
    <div>
        <span v-for="n in 10">{{ n }}</span>
    </div>
    <ul id="example3">
        <template v-for="item in items">
            <li>{{ item.msg }}</li>
            <li class="divider" role="presentation">{{ item.present }}</li>
        </template>
    </ul>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
    <script>
        var example1 = new Vue({
            el: '#example-1',
            data: {
                parentMessage: '我书架上的书',
                items: [
                    {message: '《小狗钱钱》'},
                    {message: '《观念的水位》'},
                    {message: '《自私的基因》'},
                    {message: '《算法（第4版）》'}
                ]
            }
        })
        var example2 = new Vue({
            el: '#v-for-object',
            data: {
                object: {
                    title: 'How to list in Vue',
                    author: 'Feng Liangjie',
                    publishedAt: '2022-03-15'
                }
            }
        })
        var evenNumber = new Vue({
            el: "#evenNumber",
            data: {
                sets: [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
            },
            methods: {
                even: function(numbers) {
                    return numbers.filter(function(number) {
                        return number % 2 === 0
                    })
                }
            }
        })
        var example3 = new Vue({
            el: "#example3",
            data: {
                items:[
                    {msg: '使用template信息1', present: "I'm message1"},
                    {msg: '使用template信息2', present: "I'm message2"}
                ]
            }
        })
    </script>
</body>
</html>